1 /*
2 * File: look1_binlag.c
3 *
4 * Code generated for Simulink model 'Altitude_Mode'.
5 *
6 * Model version : 1.100
7 * Simulink Coder version : 8.5 (R2013b) 08-Aug-2013
8 * C/C++ source code generated on : Mon Feb 03 08:13:10 2014
9 */
10
11 #include "rtwtypes.h"
12 #include "rtw_shared_utils.h"
13
14 real_T look1_binlag(real_T u0, const real_T bp0[], const real_T table[],
15 uint32_T maxIndex)
16 {
17 real_T y;
18 real_T frac;
19 uint32_T iRght;
20 uint32_T iLeft;
21 uint32_T bpIdx;
22
23 /* Lookup 1-D
24 Search method: 'binary'
25 Use previous index: 'off'
26 Interpolation method: 'Linear'
27 Use last breakpoint for index at or above upper limit: 'on'
28 Remove protection against out-of-range input in generated code: 'on'
29 */
30 /* Prelookup - Index and Fraction
31 Index Search method: 'binary'
32 Use previous index: 'off'
33 Use last breakpoint for index at or above upper limit: 'on'
34 Remove protection against out-of-range input in generated code: 'on'
35 */
36 if (u0 < bp0[maxIndex]) {
37 /* Binary Search */
38 bpIdx = (maxIndex >> 1U);
39 iLeft = 0U;
40 iRght = maxIndex;
41 while ((iRght - iLeft) > 1U) {
42 if (u0 < bp0[bpIdx]) {
43 iRght = bpIdx;
44 } else {
45 iLeft = bpIdx;
46 }
47
48 bpIdx = ((iRght + iLeft) >> 1U);
49 }
50
51 frac = (u0 - bp0[iLeft]) / (bp0[iLeft + 1U] - bp0[iLeft]);
52 } else {
53 iLeft = maxIndex;
54 frac = 0.0;
55 }
56
57 /* Interpolation 1-D
58 Interpolation method: 'Linear'
59 Use last breakpoint for index at or above upper limit: 'on'
60 Overflow mode: 'wrapping'
61 */
62 if (iLeft == maxIndex) {
63 y = table[iLeft];
64 } else {
65 y = table[iLeft] + (frac * (table[iLeft + 1U] - table[iLeft]));
66 }
67
68 return y;
69 }
70
71 /*
72 * File trailer for generated code.
73 *
74 * [EOF]
75 */
76
|